import {message} from 'antd';
import {formatMessage} from './intl';

export const newOrUpdateOrderValidator = (data, details) => {
    const requiredFields = [];
    if(!data || !data.brandId)
        requiredFields.push(
            formatMessage({
                id: 'validator.brandId',
                defaultMessage: '品牌'
            })
        );
    if(!data || !data.technologyActivityId)
        requiredFields.push(
            formatMessage({
                id: 'validator.technologyActivityId',
                defaultMessage: '技术升级'
            })
        );
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.requied',
            defaultMessage: '必填'
        })}`);
        return false;
    }
    if(!details || (details && details.length === 0)) {
        message.warning(formatMessage({
            id: 'validator.message.detailQuantity',
            defaultMessage: '清单不能为空！'
        }));
        return false;
    }
    if(details.find(d => d.dealerId === undefined || d.dealerId === 0)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.dealerId',
            defaultMessage: '清单中二级服务站必填!'
        })}`);
        return false;
    }
    if(details.find(d => d.vin === undefined || d.vin === 0)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.vin',
            defaultMessage: '清单中VIN必填!'
        })}`);
        return false;
    }
    if(details.find(d => d.mileage === undefined || d.mileage === 0)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.mileage',
            defaultMessage: '清单中行驶里程(KM)必填!'
        })}`);
        return false;
    }
    if(details.find(d => d.repairDate === undefined || d.repairDate === 0)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.repairDate',
            defaultMessage: '清单中维修日期必填!'
        })}`);
        return false;
    }
    if(details.find(d => d.labourType === undefined || d.labourType === 0)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.labourType',
            defaultMessage: '清单中工时类型必填!'
        })}`);
        return false;
    }
    return true;
};
